package apof.model
{
	import apof.dao.Dao;
	import apof.services.Services;
	
	public class BudgetItem extends ApofModel
	{
		public var bid:int;
		public var ctid:int;
		public var biid:int;
		
		public var amount:Number;
		
		public var budget:BudgetStc=null;
		public var consumeType:ConsumeType=null;
		
		public static function onInit():Boolean {
			var pt:Object=prototype;
			pt.classname="BudgetItem";		
			pt.fields=["biid","bid","ctid","amount"];
			pt.fieldTypes=["INT","int","int","NUMBER"];
			pt.primaryKey=["biid"];
			pt.foreignKey={	"bid":	{"linkto":BudgetStc,	"aggregate":false,	"ref":"budget",	"peerlink":"items"},
							"ctid":	{"linkto":ConsumeType,	"aggregate":false,	"ref":"consumeType","peerlink":"budgetItems"}};
			return true;
		}
		
		public function get acture():Number {
			var stDate:Date=new Date(budget.year,budget.month);
			var edDate:Date=new Date(budget.year,budget.month+1);
			var arr:Array=Services.services.getTransaction(stDate,edDate,null,consumeType.name);
			var sum:Number=0;
			for each(var tr:Transection in arr) {
				if(tr.amount<0)sum-=tr.amount;
			}
			return sum;
		}
		
		public function get name():String{
			return consumeType.name;
		}
		
		public override function get classInfo():Object {return prototype;}
		public static function get classInfo():Object {return prototype;}
	}
}